package org.example.business.endpoint.http.process;

import lombok.extern.slf4j.Slf4j;
import org.example.objevent.process.ProcessManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class MessageProcess {

    @Autowired
    private ApplicationContext applicationContext;

    private List<ProcessManager> processManagerList = new ArrayList<>();

    public void processMessage(Object msg){

        for (ProcessManager processManager: processManagerList) {

            if(null != processManager && processManager.acceptMessage(msg)){

                processManager.processMessage(msg);

                break;

            }

        }

    }

    @PostConstruct
    private void setup(){

        applicationContext.getBeansOfType(ProcessManager.class).forEach((key, value)->{
            processManagerList.add(value);

        });

    }

}
